package sketch.ounit.fuzz;

import sketch.ounit.Values;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

public class ExistingObjectFuzzerExceptionThrowingTest extends TestCase {

	public static Test suite() {
		return new TestSuite(ExistingObjectFuzzerExceptionThrowingTest.class);
	}
	
	public void setUp() {
		ExistingObjectFuzzer.setTimeLimit(2);
	}
//	
//	public void testGenerated() {
//		ExceptionThrowingCode code = new ExceptionThrowingCode();
//		code.mayThrowException();
//		code.openFlag();
//		code.openFlag();
//		code.openFlag();
//		code.doAnotherThing();
//		code.closeFlag();
//	}
	
	public void testFuzzingExistingObject() {
		/**
		 * There could be several problems with code that throws exception:
		 * 1. should we discard exception throwing sequences? //maybe not,
		 *    though the object state may not be fully-initialized 
		 * 2. should we discard error-revealing sequences? //maybe not, they are still useful
		 * 3. how about generating sequence
		 *    try  {
		 *      var10 = call some method 
		 *    } catch () {
		 *    }
		 *    var10 should not be used
		 * */
		System.out.println();
		ExistingObjectFuzzer.print_sequence = true;
		System.out.println("test testFuzzingExistingObject....");
		for(int i = 0; i < 5; i++) {
			System.out.println("The " + i + "-th round in creating test ... ");
			ExceptionThrowingCode code = new ExceptionThrowingCode();
			Values.randomFuzz(code, ExceptionThrowingCode.class);
			code.openFlag();
			Values.randomFuzz(code, ExceptionThrowingCode.class);
			code.closeFlag();
			System.out.println();
			System.out.println();
		}
		ExistingObjectFuzzer.print_sequence = false;
	}
}